package com.wiscamp.ninechapters.problems.math;

import com.wiscamp.ninechapters.common.core.ParseHelper;

import java.io.Serializable;

/**
 * 比例
 */
public class LatexProportion implements Serializable {
    /**
     * 左比分母
     */
    private int leftDenominator = 0;
    /**
     * 左比分子
     */
    private int leftNumerator = 0;

    /**
     * 右比分母
     */
    private int rightDenominator = 0;
    /**
     * 右比分子
     */
    private int rightNumerator = 0;


    public String getLatex() {
        return leftNumerator + ":" + leftDenominator + "=" + rightNumerator + ":" + rightDenominator;
    }

    public LatexProportion(int leftNumerator, int leftDenominator, int rightNumerator, int rightDenominator) {
        this.leftDenominator = leftDenominator;
        this.leftNumerator = leftNumerator;
        this.rightDenominator = rightDenominator;
        this.rightNumerator = rightNumerator;
    }

    public LatexProportion(String content) {
        var array = content.split("=");
        if (array.length == 2) {
            var arrayLeft = array[0].split(":");
            var arrayRight = array[1].split(":");

            if (arrayLeft.length == 2 && arrayRight.length == 2) {
                this.leftDenominator = ParseHelper.parseInteger(arrayLeft[1]);
                this.leftNumerator = ParseHelper.parseInteger(arrayLeft[0]);
                this.rightDenominator = ParseHelper.parseInteger(arrayRight[1]);
                this.rightNumerator = ParseHelper.parseInteger(arrayRight[0]);
            }
        }
    }
}
